#include "Card.h"
#include "Defines.h"
#include "SDL_image.h"

Card::Card()
{
		m_Image = IMG_Load("images/sOutpost.png"); // small card
		m_ImageLarge = IMG_Load("images/Outpost.png"); // Full size card
		m_Image_Tapped = IMG_Load("images/tOutpost.png"); // small, tapped card.
		x = 50;
		y = 50;
		width = SMALL_CARD_WIDTH;
		height = SMALL_CARD_HEIGHT;
		Tapped = false;
		ActionClicked = "Outpost selected";
		m_Buttons[0].setButton(35 + PREVIEW_X, 332 + PREVIEW_Y, 252, 25);
		m_Buttons[1].setButton(35 + PREVIEW_X, 361 + PREVIEW_Y, 298, 104);
}

Card::~Card()
{
	SDL_FreeSurface(m_Image);
	SDL_FreeSurface(m_ImageLarge);
	SDL_FreeSurface(m_Image_Tapped);
}

void Card::checkMouseclick(int mouseX, int mouseY)
{
	bool Clicked = false;

	for (int i = 0; i < 4; i++)
	{
		if (m_Buttons[i].isClicked(mouseX, mouseY))
		{
			DoAction(i);
			Clicked = true;
		}
	}

	if (!Clicked)
		ActionClicked = "Nope, nothing.";
}

void Card::Display(SDL_Surface* screenSurface)
{
	if (Tapped)
		drawSprite(m_Image_Tapped, screenSurface, 0, 0, x, y, width, height);
	else
		drawSprite(m_Image, screenSurface, 0, 0, x, y, width, height);
}

void Card::Display(SDL_Surface* screenSurface, int x, int y, bool FullSize)
{
	if (FullSize)
		drawSprite(m_ImageLarge, screenSurface, 0, 0, x, y, CARD_WIDTH, CARD_HEIGHT);
	else
		drawSprite(m_Image, screenSurface, 0, 0, x, y, width, height);
}

bool Card::isMouseover(int mouseX, int mouseY)
{
	if (mouseY >= y)
		if (mouseX >= x)
			if (mouseX <= x + width)
				if (mouseY <= y + height)
					return 1;

	return 0;
}

void Card::DoAction(int action)
{
	switch (action)
	{
		case 0:
			ActionClicked = "Woo, action one!";
			break;
		case 1:
			ActionClicked = "Woo, action two.";
			break;
	}
}

void Card::toggleTapped()
{
	if (Tapped)
	{
		width = SMALL_CARD_WIDTH;
		height = SMALL_CARD_HEIGHT;
		Tapped = false;
	}
	else
	{
		width = SMALL_CARD_HEIGHT;
		height = SMALL_CARD_WIDTH;
		Tapped = true;
	}
}

bool Card::isTapped()
{
	return Tapped;
}

void Card::SetXY(int x, int y)
{
	this->x = x;
	this->y = y;
}

int Card::getWidth()
{
	return width;
}

int Card::getHeight()
{
	return height;
}